import game
import pyglet
from pyglet.gl import *
import sprite


class Player(sprite.Sprite):

	group = sprite.Group()

	def __init__(self, id, name, faction, mineral, gas):
		self.id = id
		sprite.Sprite.__init__(self, self.group)
		game.state.push_handlers(self)
		self.name = name
		self.faction = faction
		self.mineral = mineral is None and 1000 or mineral # default
		self.gas = gas is None and 100 or gas # default
		self.selected = sprite.Group()
		self.tactical_view = TacticalView(self)
		game.state.push_handlers(self.tactical_view)

	def on_player_state_update(self, player_id, name, faction, mineral, gas):
		if self.id == player_id:
			self.name = name
			self.faction = faction
			self.mineral = mineral
			self.gas = gas

	def on_player_kill(self, player_id):
		if self.id == player_id:
			game.state.remove_handlers(self)
			self.kill()


class TacticalView:

	def __init__(self, player):
		self.player = player
		self.label = pyglet.text.Label('', font_name=player.faction.font_name, font_size=player.faction.font_size, anchor_x='right', anchor_y='top')

	def on_draw_tactical_hud(self):
		self.label.text = 'Min %d  Gas %d' % (self.player.mineral, self.player.gas)
		self.label.x = game.window.width - 10
		self.label.y = game.window.height - 10
		self.label.draw()

